import { eventBus, useEventBus } from '@/widgets'
import type { InteractionTip } from './types'
import { shallowRef, type ShallowRef } from 'vue'

const showTipEvent = Symbol('show-interaction-tip')

export function useInteractionTip(): ShallowRef<InteractionTip | null> {
  const ret: ShallowRef<InteractionTip | null> = shallowRef(null)
  useEventBus(showTipEvent, (e: InteractionTip | null) => (ret.value = e))
  return ret
}

export function showInteractionTip(tip: InteractionTip | undefined | null) {
  eventBus.emit(showTipEvent, tip || null)
}
